home *** CD-ROM | disk | FTP | other *** search
- #define NAME "testMemExamine"
- #define REVISION "2"
- #define ENDCODE_NOCTRLC
-
- /* Programmheader
-
- Name: testMemExamine
- Author: SDI
- Distribution: PD
- Description: tests Xpk Examine function
- Compileropts: -
- Linkeropts: -l xpkmaster
-
- 1.1 06.12.96 : fixed for new includes, added new WriteXpkFib
- 1.2 15.04.97 : included WriteXpkFib.c
- */
-
- #include <pragma/exec_lib.h>
- #include <pragma/dos_lib.h>
- #include <pragma/xpkmaster_lib.h>
- #include <exec/memory.h>
- #include "SDI_defines.h"
- #include "PrintFlags.c"
-
- struct Library *XpkBase = 0;
- ULONG DosVersion = 37;
- STRPTR buf = 0;
- BPTR fh = 0;
- struct RDArgs *rda = 0;
- struct FileInfoBlock *fib = 0;
- struct XpkFib *xfib = 0;
-
- #define PARAM "FILENAME/A"
-
- void WriteXpkFib(struct XpkFib *xfib)
- {
- STRPTR a = 0;
-
- switch(xfib->xf_Type)
- {
- case 0: a = "XPKTYPE_UNPACKED"; break;
- case 1: a = "XPKTYPE_PACKED"; break;
- case 2: a = "XPKTYPE_ARCHIVE"; break;
- }
-
- if(a)
- VPrintf("xf_Type : %s\n", &a);
- else
- VPrintf("xf_Type : %ld\n", &xfib->xf_Type);
- VPrintf(
- "xf_ULen : %ld\n"
- "xf_CLen : %ld\n"
- "xf_NLen : %ld\n"
- "xf_UCur : %ld\n"
- "xf_CCur : %ld\n"
- "xf_ID : %lx", &xfib->xf_ULen);
- a = (STRPTR) &xfib->xf_ID;
- VPrintf(" (%.4s)\n", &a);
- a = xfib->xf_Packer;
- VPrintf(
- "xf_Packer : %s\n", &a);
- VPrintf(
- "xf_SubVersion: %d\n"
- "xf_MasVersion: %d\n"
- "xf_Flags : ", &xfib->xf_SubVersion);
- {
- ULONG i = xfib->xf_Flags;
- PrintFlag(&i, XPKFLAGS_PASSWORD, "XPKFLAGS_PASSWORD");
- PrintFlag(&i, XPKFLAGS_NOSEEK, "XPKFLAGS_NOSEEK");
- PrintFlag(&i, XPKFLAGS_NONSTD, "XPKFLAGS_NONSTD");
- PrintEndFlag(i, xfib->xf_Flags);
- }
- VPrintf(
- "xf_Head : %04lx%04lx%04lx%04lx\n"
- "xf_Ratio : %ld\n", &xfib->xf_Head[0]);
- }
-
- void main(void)
- {
- UBYTE errbuf[XPKERRMSGSIZE+1];
- STRPTR filename;
-
- if(!(rda = ReadArgs(PARAM, (LONG *) &filename, 0)) ||
- !(xfib = (struct XpkFib *) AllocMem(sizeof(struct XpkFib), MEMF_ANY|MEMF_CLEAR)) ||
- !(XpkBase = OpenLibrary(XPKNAME, 0)))
- End(RETURN_FAIL);
-
- if(XpkExamineTags(xfib, XPK_InName, filename, XPK_GetError, errbuf,
- TAG_DONE))
- {
- STRPTR a = errbuf;
- VPrintf("Can't XpkExamine: %s\n", &a);
- End(RETURN_FAIL);
- }
-
- WriteXpkFib(xfib);
-
- if(!(fh = Open(filename, MODE_OLDFILE)) ||
- !(fib = (struct FileInfoBlock *) AllocDosObject(DOS_FIB, 0)) ||
- !(ExamineFH(fh, fib)) ||
- !(buf = (STRPTR) AllocMem(fib->fib_Size, MEMF_ANY)) ||
- Read(fh, buf, fib->fib_Size) != fib->fib_Size)
- End(RETURN_FAIL);
-
- if(XpkExamineTags(xfib, XPK_InBuf, buf, XPK_InLen, fib->fib_Size,
- XPK_GetError, errbuf, TAG_DONE))
- {
- STRPTR a = errbuf;
- VPrintf("Can't XpkExamine: %s\n", &a);
- End(RETURN_FAIL);
- }
-
- WriteXpkFib(xfib);
-
- End(RETURN_OK);
- }
-
- void end(void)
- {
- if(fh) Close(fh);
- if(xfib) FreeMem(xfib, sizeof(struct XpkFib));
- if(buf) FreeMem(buf, fib->fib_Size);
- if(XpkBase) CloseLibrary(XpkBase);
- if(fib) FreeDosObject(DOS_FIB, fib);
- if(rda) FreeArgs(rda);
- }
-
-